home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 11: TSX-11 / Linux Cubed Series 11 - TSX-11 Vol 1.iso / sbin / bootutil.1 / bootutil / bootutils / mount / fstab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-01  |  1.7 KB  |  93 lines

  1. /* $Header: /usr/src/mount/RCS/fstab.c,v 1.1 1992/09/06 13:30:53 root Exp root $ */
  2.  
  3. #include "fstab.h"
  4. #include <stdio.h>
  5.  
  6. #define streq(s, t)    (strcmp ((s), (t)) == 0)
  7.  
  8. /* These routines are superceded by mntent(3), but I use them for
  9.    convenience.  Mntent(3) is used in the implementation, so be
  10.    very careful about the static buffers that are returned.  */
  11.  
  12.  
  13. static FILE *F_fstab = NULL;
  14.  
  15. /* Open fstab or rewind if already open.  */
  16. int
  17. setfsent (void)
  18. {
  19.   if (F_fstab)
  20.     return (fseek (F_fstab, 0L, SEEK_SET) == 0);
  21.  
  22.   F_fstab = setmntent (_PATH_FSTAB, "r");
  23.   return (F_fstab != NULL);
  24. }
  25.  
  26. /* Close fstab.  */
  27. void
  28. endfsent (void)
  29. {
  30.   endmntent (F_fstab);
  31. }
  32.  
  33. /* Return next entry in fstab, skipping ignore entries.  I also put
  34.    in some ugly hacks here to skip comments and blank lines.  */
  35. struct mntent *
  36. getfsent (void)
  37. {
  38.   struct mntent *fstab;
  39.  
  40.   if (!F_fstab && !setfsent())
  41.     return 0;
  42.  
  43.   for (;;)
  44.     {
  45.       fstab = getmntent (F_fstab);
  46.       if (fstab == NULL)
  47.     {
  48.       if (!feof (F_fstab) && !ferror (F_fstab))
  49.         continue;
  50.       else
  51.         break;
  52.     }
  53.       else if ((*fstab->mnt_fsname != '#')
  54.            && !streq (fstab->mnt_type, MNTTYPE_IGNORE))
  55.     break;
  56.     }
  57.   return fstab;
  58. }
  59.  
  60. /* Find the dir FILE in fstab.  */
  61. struct mntent *
  62. getfsfile (const char *file)
  63. {
  64.   struct mntent *fstab;
  65.  
  66.   /* Open or rewind fstab.  */
  67.   if (!setfsent ())
  68.     return 0;
  69.  
  70.   while ((fstab = getfsent ()))
  71.     if (streq (fstab->mnt_dir, file))
  72.       break;
  73.  
  74.   return fstab;
  75. }
  76.  
  77. /* Find the device SPEC in fstab.  */
  78. struct mntent *
  79. getfsspec (const char *spec)
  80. {
  81.   struct mntent *fstab;
  82.  
  83.   /* Open or rewind fstab.  */
  84.   if (!setfsent())
  85.     return 0;
  86.  
  87.   while ((fstab = getfsent ()))
  88.     if (streq (fstab->mnt_fsname, spec))
  89.       break;
  90.  
  91.   return fstab;
  92. }
  93.